package pers.xuyong.strive.datastruct.order;

/**
 * 排序
 *
 * @author billymac
 * @version 1.0
 * @date 17/5/23  下午2:23
 * @since JDK1.8
 */
public abstract class AbstractOrder<E extends Number> implements Order<E> {


    @Override
    public void swap(E[] ts, int i, int j) {
        if (ts == null)
            throw new NullPointerException("ts can not be null");

        if(i < 0 || j < 0 || i >= ts.length || j > ts.length)
            throw new ArrayIndexOutOfBoundsException("i = " + i + " or j = " + j + " over ts limit!");

        E tmp = ts[i];
        ts[i] = ts[j];
        ts[j] = tmp;
    }

    /**
     * 数据内容校验
     * @param ts
     */
    public void valid(E[] ts) {
        if(ts == null)
            throw new NullPointerException("ts can not be null!");
    }
}
